package com.googlecode.gamedroid.event.source;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;

import com.googlecode.gamedroid.R;

public class RoundedButton extends GameButton implements EventSource
{
	public RoundedButton(Context context, AttributeSet attrs, int defStyle)
	{
		super(context, attrs, defStyle);
		setStyle();
	}

	public RoundedButton(Context context, AttributeSet attrs)
	{
		super(context, attrs);
		setStyle();
	}

	public RoundedButton(Context context)
	{
		super(context);
		setStyle();
	}

	private static final int PADDING = 5;
	
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
	{
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		int w = getMeasuredWidth();
		int h = getMeasuredHeight();
		
		if(w < h)
			w = h;
		else if(h < w)
			h = w;
		
		int measuredW = View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.getMode(getMeasuredWidthAndState()));
		int measuredH = View.MeasureSpec.makeMeasureSpec(h, View.MeasureSpec.getMode(getMeasuredHeightAndState()));
		
		setMeasuredDimension(measuredW, measuredH);
	}
	
	protected void setStyle()
	{
		setBackgroundResource(R.drawable.rounded_button);
		setPadding(PADDING, PADDING, PADDING, PADDING);
		setGravity(Gravity.CENTER);
	}
}
